import axios from 'axios';
import iconv from 'iconv-lite';

export async function getAddress(ip?: string) {
    const res = await axios('http://whois.pconline.com.cn/ipJson.jsp', {
        method: 'get',
        params: {
            ip: ip,
            json: true,
        },
        responseType: 'arraybuffer',
    });
    const gbk = iconv.decode(Buffer.from(res.data), 'gb2312');
    const utf8 = iconv.encode(gbk, 'utf8').toString();
    return JSON.parse(utf8);
}
